﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 作业3
{
    class Class1
    {
        
        static void Main(string[] args)
        {
            double sum = 0;
            Random r = new Random();

            ArrayList shapes = new ArrayList();
            //随机生成十个形状对象
            for (int i = 0; i < 10; i++)
            {
                int j = r.Next(1,100);
                switch (j%3){
                    case 0:shapes.Add(new Rectangle(j, j -1));break;
                    case 1:shapes.Add(new Square(j));break;
                    case 2:shapes.Add(new Circle(j));break;
                    default:break;
                }
            }
            //计算面积之和
            foreach (Shape shape in shapes)    
            {
                sum += shape.area();
            }
            Console.WriteLine("总面积为{0:f}",sum);
            
        }
    }
    //形状抽象类
    abstract class Shape
    {
        public abstract double area();//计算面积
        public abstract bool isRight();//判断形状是否正确

    }

    //长方形类
    class Rectangle:Shape
    {
        private double length,width;//长，宽字段

        public Rectangle(double length, double width)
        {
            this.length = length;
            this.width = width;
        }

        public double Length { get => length; set => length = value; }
        public double Width { get => width; set => width = value; }
        
        public override double area()
        {
            return length * width;
        }
        public override bool isRight()
        {
            if (length >= 0 && width >= 0) return true;
            else return false;
        }
    }
    //正方形类
    class Square : Shape
    {
        private double length;//边长字段

        public Square(double length)
        {
            this.Length = length;
        }

        public double Length { get => length; set => length = value; }

        public override double area()
        {
            return length * length;
        }

        public override bool isRight()
        {
            if (length >= 0) return true;
            else return false;
        }
    }
    //圆形类
    class Circle : Shape
    {
        private double radius;//半径字段

        public Circle(double radius)
        {
            this.radius = radius;
        }

        public override double area()
        {
            return Math.PI * radius * radius;
        }

        public override bool isRight()
        {
            if (radius >= 0) return true;
            else return false;
        }
    }
}
